package com.huowenjie;

import com.alibaba.fastjson.JSON;
import com.huowenjie.dao.DingDao;
import com.huowenjie.dao.UserDao;
import com.huowenjie.entity.Ding;
import com.huowenjie.entity.User;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.Date;
import java.util.Optional;

@SpringBootTest
@RunWith(SpringRunner.class)
public class Tets {

    @Autowired
    UserDao userDao;

    @Autowired
    DingDao dingDao;

    //添加用户
    @Test
    public void adduser(){

        for (int i = 0; i < 10; i++) {
            User user = new User();
            user.setName("张三"+i);
            user.setSex("男");
            user.setJiguan("汉");
            user.setAddress("河北");
            user.setPsw("123");
            user.setBirth("2019-11-11");
            userDao.save(user);
        }

    }


    //添加订单
    @Test
    public void dingadd(){
        for (int i = 0; i < 10; i++) {
            Ding ding = new Ding();
            ding.setJin("120");
            ding.setDhao("111"+i);
            ding.setStatus("1");
            ding.setUserid(3);
            dingDao.save(ding);
        }
    }


    //根据用户id查询
    @Test
    public void select(){
        Optional<User> byId = userDao.findById(1l);
        System.out.println(JSON.toJSONString(byId));
    }

    //日期查询
    @Test
    public void brith(){
        User byBirthEquals = userDao.findByBirthEquals("2019-11-12");
        System.out.println(JSON.toJSONString(byBirthEquals));
    }

    //删除
    @Test
    public void del(){


        userDao.deleteById(2l);


    }

}
